package cn.wenhe9.yygh.hosp.controller;

import cn.wenhe9.yygh.common.result.ResultResponse;
import cn.wenhe9.yygh.hosp.service.HospitalService;
import cn.wenhe9.yygh.model.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author DuJinliang
 * 2022/3/28
 */
@Api(tags = "医院管理")
//@CrossOrigin
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Resource
    private HospitalService hospitalService;

    /**
     * 多条件分页查询医院信息
     * @param page 当前页
     * @param limit 每页显示的条数
     * @param hospitalQueryVo 多条件对象
     * @return ResultResponse
     */
    @GetMapping("/list/{page}/{limit}")
    public ResultResponse listHosp(
            @PathVariable(name = "page") @DefaultValue("1") int page,
            @PathVariable(name = "limit") @DefaultValue("5") int limit,
            HospitalQueryVo hospitalQueryVo
    ){
        return hospitalService.findHospitalsByPage(hospitalQueryVo, page, limit);
    }

    /**
     * 更新上线状态
     * @param id String
     * @param status Integer
     * @return ResultResponse
     */
    @ApiOperation("更新上线状态")
    @PutMapping("/lock/{id}/{status}")
    public ResultResponse lock(
            @ApiParam(name = "id", value = "医院 id", required = true)
            @PathVariable(name = "id") String id,
            @ApiParam(name = "status", value = "状态（0 ：未上线 1 ：已上线）", required = true)
            @PathVariable(name = "status") Integer status
    ){
        return hospitalService.updateStatus(id, status);
    }

    /**
     * 医院详情信息
     * @param id String
     * @return ResultResponse
     */
    @ApiOperation("医院详情信息")
    @GetMapping("/detail/{id}")
    public ResultResponse showHospDetail(@PathVariable(name = "id") String id){
        return hospitalService.findHospDetail(id);
    }
}
